<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" width="800px">
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="130px"
      v-loading="formLoading"
    >
      <el-form-item label="租住地址" prop="roomRentId">
        {{formData.rentAddr_}}
      </el-form-item>
      <el-form-item label="租客信息" prop="roomRentId">
        <template v-if="formData.rentUserResp">
          {{formData.rentUserResp.name}}（{{formData.rentUserResp.mobile}}）
        </template>
      </el-form-item>
      <el-form-item label="房租金额" prop="rentAmount">
        {{formData.rentAmount}}
      </el-form-item>
      <el-form-item label="房租押金" prop="depositAmount">
        {{formData.depositAmount}}
      </el-form-item>
      <el-form-item label="收租周期" prop="payMonthUnit">
        每{{ formData.payMonthUnit }}个月收租一次
      </el-form-item>
      <el-form-item label="生效日期" prop="effectTime" >
        {{formatDate(formData.effectTime,'YYYY-MM-DD')}}
      </el-form-item>
      <el-form-item label="线上支付" prop="onlinePayFlag">
        {{formData.onlinePayFlag?"是":"否"}}
      </el-form-item>
      <el-form-item label="合同图片" prop="contractImages">
        <UploadImgs v-model="formData.contractImages" :limit="1" :disabled="true"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <!-- <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button> -->
      <el-button @click="dialogVisible = false">关闭</el-button>
    </template>
  </Dialog>
</template>
<script setup lang="ts">
import { RentContractApi, RentContractVO } from '@/api/zwsj/rentcontract'

/** 房租合同 表单 */
defineOptions({ name: 'RentContractView' })
import { formatDate } from '@/utils/formatTime'

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formType = ref('') // 表单的类型：create - 新增；update - 修改
const formData = ref({
  id: undefined,
  roomRentId: undefined,
  rentAmount: undefined,
  depositAmount: undefined,
  payMonthUnit: undefined,
  effectTime: undefined,
  onlinePayFlag: undefined,
  contractImages: [],
})
const formRules = reactive({
})
const formRef = ref() // 表单 Ref

/** 打开弹窗 */
const open = async (type: string, id?: number) => {
  dialogVisible.value = true
  //dialogTitle.value = t('action.' + type)
  dialogTitle.value = '详细'
  formType.value = type
  // 修改时，设置数据
  if (id) {
    formLoading.value = true
    try {
      const data = await RentContractApi.getRentContract(id)
      formData.value = data
    } finally {
      formLoading.value = false
    }
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
</script>